home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Logica 2.00 / Logica Examples 1 / Circuit.ex < prev    next >
Encoding:
Text File  |  1993-01-02  |  2.3 KB  |  74 lines  |  [TEXT/CGT1]

  1. \ Circuit.ex2
  2.  
  3. \ Example problem for use with LOGICA™.
  4. \ Copyright © 1992, LogicLab.  All rights reserved.
  5.  
  6. \ This example demonstrates Hyperresolution and demodulation.  
  7. \ The goal is to find an electronic circuit, containing no more than
  8. \ three 2-input NAND gates, which computes the OR function.
  9.  
  10. Logic: HyperRes;
  11. function: n, NAND, circuit, GateCount;
  12. predicate: output;
  13. constant: in1, in2;
  14.  
  15. Demodulate:
  16. Rewrite(n(0,x),1);    \ nand gate operation
  17. Rewrite(n(x,0),1);    \ nand gate operation
  18. Rewrite(n(1,1),0);    \ nand gate operation
  19.  
  20. \ The format for the atoms of the following clauses 
  21. \ is "output({x,x1,x2,x3},circuit(x4))",
  22. \ where the list {x, x1, x2, x3} is the 'truth table' for the circuit 
  23. \ having binary inputs in1, in2 and circuit diagram x4.
  24. \
  25. \               in2 = 0    in2 = 1
  26. \   in1 = 0         x          x1
  27. \   in1 = 1        x2          x3
  28. \
  29. \ The truth table is represented by the list of its entries, reading
  30. \ across the rows.
  31.  
  32. Axiom:
  33. \ Represent the fact that if we can develop two circuits x4 and x9, 
  34. \ then we can develop a circuit which computes the NAND X4 and x9: 
  35.  
  36.    ~output({x,x1,x2,x3},circuit(x4),GateCount(x10)) | 
  37.       ~output({x5,x6,x7,x8},circuit(x9),GateCount(x11)) |
  38.     output({n(x,x5),n(x1,x6),n(x2,x7),n(x3,x8)},
  39.     circuit(NAND(x4,x9)),GateCount(x10 + x11 + 1)) |
  40.     WHILE((x10 + x11 + 1) <= 3);
  41.  
  42. Assert:
  43. \ Represent the truth tables for the two possible 'identity functions':
  44. \ the first outputs in1, the second outputs in2.
  45. \ The truth-table for the function "output = in1" is
  46. \
  47. \   [in1]        in2 = 0    in2 = 1
  48. \   in1 = 0         0          0
  49. \   in1 = 1         1          1
  50. \
  51. \ Using the conventional ordering stated above (reading across the rows),
  52. \ this is represented as {0,0,1,1}:
  53.  
  54. output({0,0,1,1},circuit(in1),GateCount(0));    \ output = in1
  55.  
  56. \ The truth-table for the function "output = in2" is
  57. \
  58. \   [in2]        in2 = 0    in2 = 1
  59. \   in1 = 0         0          1
  60. \   in1 = 1         0          1
  61. \
  62. \ Again, reading across the rows, this is represented as {0,1,0,1}:
  63.  
  64. output({0,1,0,1},circuit(in2),GateCount(0));    \ output = in2
  65.  
  66. \ Express the truth table for the desired result: 
  67. \ the OR of two inputs, from any circuit diagram
  68. \ (here negated to assert the non-existence of a solution).
  69.  
  70. ~output({0,1,1,1},circuit(x),GateCount(x1));
  71.  
  72.  
  73.  
  74.